<extend name="Index:base" />
<block name="stylecss">
    <style>
        .sel{
            height:auto;
            overflow: hidden;
            border:1px solid #CCC;
            padding:0px;
            margin-bottom: 5px;
        }
        .sel-heading{
            background: #EEE;
            height:35px;
            margin: 0px;
            color: #2c79a6;
        }
        .sel label{
            height: 30px;
            line-height: 35px;
            padding-left: 10px;
            float: left;
            margin-right: 10px;
        }
        .sel-input input{
            border:1px solid bule;
        }
        .sel-title{
            display: block;
            height:35px;
            line-height: 35px;
            margin: 0px;
            font-size: 16px;
        }
        .sel-body{
            padding:20px;
            height:auto;
            overflow: hidden;
        }
        .childsel{
            float: left;
            margin: 5px;
        }
    </style>
</block>
<block name="content">
    <div class="main-content">
        <div class="breadcrumbs" id="breadcrumbs">
            <script type="text/javascript">
                try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
            </script>

            <!-- 面包屑导航 -->
            <ul class="breadcrumb">
                <li>
                    <i class="icon-home home-icon"></i>
                    <a href="{:U('Admin/Index/index')}">首页</a>
                </li>
                <li>
                    <a href="{:U('Admin/Goodsbrand/index')}">{$page['title']['prev']}</a>
                </li>
                <li class="active">
                    {$page['title']['current']}
                </li>
            </ul><!-- .breadcrumb -->

        </div>

        <div class="page-content">

            <!-- 页面导航 -->
            <div class="page-header">
                <h1>
                    {$page['title']['current']}
                    <a class="btn btn-info btn-sm pull-right" href="{:U('Admin/Goodsbrand/index')}">
                        <i class="icon-reply icon-only"></i>
                    </a>
                </h1>
            </div>

            <div class="row" style="margin-top:35px;">
                <div class="col-xs-12">
                    <form class="form-horizontal" role="form" action="{:U('Admin/Goodsbrand/updataBrand')}" method="post" enctype="multipart/form-data">
                        <input type="hidden" name="bid" value="{$Think.get.id}">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right"> 品牌名称 </label>
                            <div class="col-sm-10">
                                <input class="col-xs-10 col-sm-5" type="text" placeholder="请填写品牌名称" value="{$bname['bname']}" name="bname">
                            </div>
                        </div>
                        <div class="form-group" style="margin-bottom:0px;">
                            <label class="col-sm-2 control-label no-padding-right"> 品牌标识 </label>
                            <div class="col-sm-10">
                                <div class="ace-file-input no-padding col-xs-10 col-sm-5">
                                    <input style="height:30px;" type="file" id="id-input-file-2" name="brandpic" />
                                </div>
                                <img class="full-right" style="margin-left:10px;" src="__PUBLIC__/Uploads/{$bname['brandpic']|explode='/',###|implode='/th_',###}" height="30">
                            </div>
                        </div>
                        <!-- 选择品牌 -->
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right"> 选择拥有产品 </label>
                            <div class="col-sm-10" id="selparent">
                                <div id="accordion" class="col-xs-10 col-sm-12 no-padding">
                                    <div class="sel-group" id="selclass">
                                        <volist name="data" id="val">
                                            <div class="sel">
                                                <label>
                                                    <input type="checkbox" id="checkAll-{$i}" class="ace ace-checkbox-2"/>
                                                    <span class="lbl">全选</span>
                                                </label>
                                                <div class="sel-heading" data-toggle="collapse" data-toggle="collapse" data-parent="#selclass" data-target="#sel-{$i}">
                                                    <span class="sel-title">
                                                        {$val['cname']}
                                                    </span>
                                                </div>
                                                <div id="sel-{$i}" class="sel-collapse collapse in">
                                                    <div class="sel-body" id="check-{$i}">
                                                        <foreach name="childs[$i-1]" item="vo">
                                                            <if condition="$vo['isbottom'] eq 1">
                                                                <div class="childsel">
                                                                    <input type="checkbox" class="ace ace-checkbox-2" name="team[]" value="{$vo['cid']}" {$vo['ishave']?'checked':''}/>
                                                                    <span class="lbl">{$vo['cname']}</span>
                                                                </div>
                                                            <else/>
                                                                <div class="childsel" style="margin-left:10px;">
                                                                    <span class="lbl" style="color:#05A;">{$vo['cname']}：</span>
                                                                </div>
                                                            </if>
                                                        </foreach>
                                                    </div>
                                                </div>
                                            </div>
                                        </volist>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- 选择品牌结束 -->

                        <div class="clearfix form-actions">
                            <div class="col-md-offset-2 col-md-10">
                                <button class="btn btn-info" type="submit">
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>
                                &nbsp; &nbsp; &nbsp;
                                <button class="btn" type="reset">
                                    <i class="icon-undo bigger-110"></i>
                                    重置
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</block>
<block name="privatejs">
    <script type="text/javascript">
        $(function(){
            //设置当前页面的菜单高亮显示 开始
            var nownav = '#sidebar a[href*=Goodsbrand]';
            var parentattr = $(nownav).parent().parent().attr("class");
            $(nownav).parent().addClass('active');
            if (parentattr == 'submenu') {
                $(nownav).parent().parent().parent().addClass('active open');
            };
            //设置当前页面的菜单高亮显示 结束

            //全选默认状态
            for (var i = 1; i <= $('#selclass').children().length; i++) {
                var $tmp = $('#check-'+i+' :checkbox');
                if ($('#check-'+i).children().length) {
                    $('#checkAll-'+i).prop('checked',$tmp.length == $tmp.filter(':checked').length);
                };
            };

            //全选 
            $("[id^=checkAll-]:checkbox").on('click',function(){
                var num = $(this).prop('id').split('-')[1];
                var divs = "#check-"+num;
                $(divs+" :checkbox").prop("checked",this.checked);
            });
           
            $('[name^=team]:checkbox').click(function(){
                var num = $(this).parent().parent().prop('id').split('-')[1];
                var $tmp = $('#check-'+num+' :checkbox');
                $("#checkAll-"+num).prop('checked',$tmp.length==$tmp.filter(':checked').length);
            });

            $('#id-input-file-2').ace_file_input({
                no_file:'选择广告图片 ...',
                btn_choose:'上传',
                btn_change:'修改',
                droppable:false,
                onchange:null,
                thumbnail:false //| true | large
                //whitelist:'gif|png|jpg|jpeg'
                //blacklist:'exe|php'
                //onchange:''
                //
            }); 
        
            //文件上传
            $('#id-file-format').removeAttr('checked').on('change', function() {
                var before_change
                var btn_choose
                var no_icon
                if(this.checked) {
                    btn_choose = "Drop images here or click to choose";
                    no_icon = "icon-picture";
                    before_change = function(files, dropped) {
                        var allowed_files = [];
                        for(var i = 0 ; i < files.length; i++) {
                            var file = files[i];
                            if(typeof file === "string") {
                                //IE8 and browsers that don't support File Object
                                if(! (/\.(jpe?g|png|gif|bmp)$/i).test(file) ) return false;
                            }
                            else {
                                var type = $.trim(file.type);
                                if( ( type.length > 0 && ! (/^image\/(jpe?g|png|gif|bmp)$/i).test(type) )
                                        || ( type.length == 0 && ! (/\.(jpe?g|png|gif|bmp)$/i).test(file.name) )//for android's default browser which gives an empty string for file.type
                                    ) continue;//not an image so don't keep this file
                            }
                            
                            allowed_files.push(file);
                        }
                        if(allowed_files.length == 0) return false;
        
                        return allowed_files;
                    }
                }
                else {
                    btn_choose = "Drop files here or click to choose";
                    no_icon = "icon-cloud-upload";
                    before_change = function(files, dropped) {
                        return files;
                    }
                }
                var file_input = $('#id-input-file-3');
                file_input.ace_file_input('update_settings', {'before_change':before_change, 'btn_choose': btn_choose, 'no_icon':no_icon})
                file_input.ace_file_input('reset_input');
            });
        });
    </script>
</block>